<template>
  <div class="list" @click="goSearch($event)">
    <div class="title">百度热搜榜</div>
    <template v-if="bdRank.length">
      <div class="listItem"  v-for="item in bdRank" :key="item.index" :data-name="item.word">
        <div class="cover">
          <img :src="item.img" alt="">
        </div>
        <div class="coverRight">
          <div class="title">{{item.word}}</div>
          <div class="desc">{{item.desc}}</div>
          <div class="bottom">
            <div v-for="v,i in item.show" :key="i" class="info">{{v}}</div>
          </div>
        </div>
      </div>
    </template>
    <Skeleton v-else />
  </div>
</template>

<script>
import { mapState } from 'vuex'
import Skeleton from '../topRank/skeleton.vue'
export default {
  name:'BookList',
  components: { Skeleton },
  mounted (){
    if (this.bdRank.length === 0){
      this.$store.dispatch('bdRank')
    }
  },
  computed: {
    ...mapState({
      bdRank: (state) => state.novel.bdRank
    })
  },
  methods: {
    goSearch (e){
      let searchKey = ''
      for (let i = 0; i < e.path.length; i++){
        searchKey = e.path[i].dataset.name
        if (searchKey) break
      }
      this.$router.push({ name: 'Search', params:{ searchKey } })
    }
  }
}
</script>

<style lang="less" scoped>
.list{
  margin: 1em 5%;
  border-radius: 10px;
  padding: 8px ;
  min-height: 20em;
  background-color: var(--box-bg);
  .title{
    font-size: 1.5em;
    line-height: 2;
  }
  .listItem{
    margin-bottom: 1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .cover{
      width: 20%;
      border-radius: 5px;
      overflow: hidden;
      img{
        width: 100%;
      }
    }
    .coverRight{
      width: 80%;
      padding: 0 5%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      color: var(--font-color);
      &>div{
        margin-bottom:.35em;
      }
      .title{
        font-size: 1em;
      }
      .desc{
        font-size: .5em;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        color: var(--icon-color);
      }
      .bottom{
        display: flex;
        font-size: .5em;
        justify-content: space-between;
      }
    }
  }

}
</style>
